package com.bdqn.t350.ch09.exception;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class LoginHandler {

    private static final Logger log = LoggerFactory.getLogger(LoginHandler.class);

    @ExceptionHandler(value = {LoginException.class})
    public String loginExceptionHandle(Model model, LoginException e) {
        log.info("登录异常");
        model.addAttribute("msg", e.getMessage());
        return "/login";
    }

    @ExceptionHandler(value = {ArithmeticException.class})
    public String arithmeticExceptionHandle(Model model, Exception e) {
        log.info("算数异常");
        model.addAttribute("msg", new ArithmeticException("算数异常"));
        return "/error";
    }

    @ExceptionHandler(value = {RuntimeException.class})
    public String runtimeExceptionHandle(Model model, Exception e) {
        log.info("异常....");
        model.addAttribute("msg", new RuntimeException("异常"));
        return "/error/adderror";
    }
}
